import string,cgi,time
from os import curdir, sep
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServerimport twitter

import urllib

api = twitter.Api(username='miaoyu', password='miaoyu123')

class MyHandler(BaseHTTPRequestHandler):
	def do_GET(self):
		try:
			self.send_response(200)
			self.send_header('Content-type',	'text/html')
			self.end_headers()
			self.wfile.write("Mail Sent")           
			msg = self.path[11:].replace("%20", " ")
			
			if len(msg)>140:
				msg = msg[:137]+"..."
			print urllib.unquote(msg)
			status = api.PostUpdate(msg)
			print status.text
			return
		except IOError:
			self.send_error(404,'File Not Found: %s' % self.path)
     
def main():
    try:
        server = HTTPServer(('', 8088), MyHandler)
        print 'started httpserver...'
        server.serve_forever()
    except KeyboardInterrupt:
        print '^C received, shutting down server'
        server.socket.close()

if __name__ == '__main__':
    main()
